package commercial.src;
import java.util.ArrayList;
import java.util.List;
public class Order {
    private User user;
    private List<Product> productList;
    public Order(User user){
        this.user=user;
        this.productList=new ArrayList<>();
    }
    public void addProduct(Product product){
        productList.add(product);
    }
    public double calculateTotal(){
        double total=0;
        for (Product p:productList){
            total+=p.getPrice();
        }
        return  total;
    }
    public void displayOrder(){
        System.out.println("订单用户：");
        user.displayInfo();
        System.out.println("商品列表：");
        for (Product p:productList){
            p.displayInfo();
        }
        System.out.printf("总价：%.2f\n", calculateTotal());

    }
    public void pay(Payment payment) {
        double amount = calculateTotal();
        payment.pay(amount);
    }

}
